package au.edu.swin.MelbourneMap;

import java.util.*;
import java.awt.geom.*;

/**
 * Data structure to define a road comprised of Path2D of points. 
 *
 * @author  Alexis Wellavize (s/n: 6033482)<br/>
 *           Dotan Tamir (s/n: 6532969)
 * @since   v1, created:  25/09/2012
 * @version v1, modified:  25/09/2012
 *
 */
 
class Road
{
    /// Name of the road
    private String roadName;
    // Has the road been clicked?
    private Boolean isSelected;
    /// Path2D segments for road
    private Path2D path;
    // LinkedList of nodes the road contains
    private LinkedList<Point2D> nodes = new LinkedList<Point2D>();
    // Road visibility
    private boolean visibility;
    // Distance of road (in meters)
    private double distance = 0.0;
    // Number of lanes
    private int lanes = 0;
    // Type of road
    private String type;
   
    // Overloaded constructor
    public Road( String roadName )
    {
    	this.roadName = roadName;
        this.isSelected = false;
    }
    
    public Road(
        String roadname, Point2D p1, Point2D p2,
        double distance, String type, int lanes )
    {
        this.roadName = roadName;
        this.distance = distance;
        this.type = type;
        this.lanes = lanes;
        nodes.addFirst( p1 );
        nodes.addLast( p2 );
        this.isSelected = false;        
    }
    
    
    // Accessor methods

    public String getName()
    {
    	return roadName;
    }
    
    public void addPoints( LinkedList<Point2D> points )
    {
        nodes.removeLast();
        nodes.addAll( points );
    }
    
    public LinkedList<Point2D> getNodes()
    {
        return nodes;
    }
    
    public boolean getVisibility()
    {
        return visibility;
    }
    
    public double getDistance()
    {
        return distance;
    }
    
    public Point2D getFirstNode()
    {
        return nodes.getFirst();
    }
    
    public Point2D getLastNode()
    {
        return nodes.getLast();
    }    
    
    public int getLanes()
    {
        return lanes;
    }
    
    public String getType()
    {
        return type;
    }
    
	public boolean getIsSelected()
    {
		return isSelected;
	}    
    
    // Mutator methods
    
    public void setName( String roadName )
    {
    	this.roadName = roadName;
    }
    
    public void addDistance( double distance )
    {
        this.distance += distance;
    }
    
    public void addFirstNode( Point2D node )
    {
        if ( !nodes.contains( node ) )
            nodes.addFirst( node );
    }
    
    public void addLastNode( Point2D node )
    {
        if ( !nodes.contains( node ) )
            nodes.addLast( node );
    }
   
    public void setLanes( int lanes )
    {
    	this.lanes = lanes;
    }

    public void setType( String type )
    {
    	this.type = type;
    }
    
    public void setVisibility( boolean visibility )
    {
        this.visibility = visibility;
    }
    
	public void setIsSelected( boolean isSelected )
    {
		this.isSelected = isSelected;
	}   

    public Path2D getPath()
    {
        path = new Path2D.Double();
        for ( int i = 0; i < nodes.size() - 1; i++ )
        {
            path.moveTo( nodes.get(i).getX(), nodes.get(i).getY() );
            path.lineTo( nodes.get(i + 1).getX(), nodes.get(i + 1).getY() );
        }
        return path;
    }
}
